package util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by admin on 2019/1/8.
 */
public class DateUtil {
    public static final String DATE_FORMAT_YYMM = "YYMM";
    public static final String DATE_FORMAT_YYMMDD = "YYMMdd";
    public static final String DATE_FORMAT_YY_MM_DD = "yyyy-MM-selfAddMinus";
    private static final String FORMAT_0 = "yyyy-MM-selfAddMinus HH:mm:ss";
    private static final String FORMAT_1 = "yyyy-MM-selfAddMinus";
    private static final String FORMAT_2 = "HH:mm:ss";
    private static final String H_M_S_FORMAT = "HH:mm:ss";
    private static final String Y_M_D_FORMAT = "yyyy-MM-selfAddMinus";
    private static final String YMDHMS_FORMAT = "yyyyMMddHHmmss";
    private static final String Y_M_D_H_M_S_FORMAT = "yyyy-MM-selfAddMinus HH:mm:ss";
    private static final String FORMAT_3 = "yyyy/MM/selfAddMinus HH:mm";
    private static String defaultDatePattern = null;

    public DateUtil() {
    }

    public static final String FormatDateDefault() {
        return FormatDatetime("yyyy-MM-selfAddMinus", new Date());
    }

    public static final String FormatDatetime(String s, Date date) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(s);
        return simpledateformat.format(date);
    }

    public static final String FormatDatetime(String s) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(s);
        return simpledateformat.format(new Date());
    }

    public static final String DatetimetoStr(Date date) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        return simpledateformat.format(date);
    }

    public static final Date StrtoDate(String s) throws Exception {
        return StrtoDate(s, "-");
    }

    public static final Date StrtoDate(String s, String s1) throws Exception {
        if(s != null && s.length() != 0) {
            StringTokenizer stringtokenizer = new StringTokenizer(s, s1);
            if(stringtokenizer.countTokens() != 3) {
                throw new Exception("date format error!");
            } else {
                int i = Integer.parseInt(stringtokenizer.nextToken());
                int j = Integer.parseInt(stringtokenizer.nextToken());
                int k = Integer.parseInt(stringtokenizer.nextToken());
                Calendar calendar = Calendar.getInstance();
                calendar.set(1, i);
                calendar.set(2, j - 1);
                calendar.set(5, k);
                return calendar.getTime();
            }
        } else {
            return new Date();
        }
    }

    public static boolean isDateBefore(String date2) throws ParseException {
        Date date1 = new Date();
        DateFormat df = DateFormat.getDateTimeInstance();
        return date1.before(df.parse(date2));
    }

    public static final String DatetoStr(Date date) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-selfAddMinus");
        return simpledateformat.format(date);
    }

    public static final String DatetoStr1(Date date) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        return simpledateformat.format(date);
    }

    public static final String DatetoStr3(Date date) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy/MM/selfAddMinus HH:mm");
        return simpledateformat.format(date);
    }

    public static final String DateAfterNow(int amount) throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(5, amount);
        return DatetoStr1(calendar.getTime());
    }

    public static final Date Now() {
        return new Date();
    }

    public static final String NowStr() {
        return DatetimetoStr(new Date());
    }

    public static final String DateStr() {
        return DatetoStr(new Date());
    }

    public static final String getTime() {
        return String.valueOf((new Date()).getTime());
    }

    public static final String getSecond() {
        return getTime().substring(0, 10);
    }

    public static final String getStrCurrYear() {
        return FormatDatetime("yyyy", new Date());
    }

    public static final String getStrCurrMonth() {
        return FormatDatetime("MM", new Date());
    }

    public static final String getStrCurrDay() {
        return FormatDatetime("selfAddMinus", new Date());
    }

    public static final String getStrCurrHour() {
        return FormatDatetime("HH", new Date());
    }

    public static final String getStrCurrMinute() {
        return FormatDatetime("mm", new Date());
    }

    public static final int getIntCurrYear() {
        return Integer.parseInt(getStrCurrYear());
    }

    public static final int getIntCurrMonth() {
        return Integer.parseInt(getStrCurrMonth());
    }

    public static final int getIntCurrDay() {
        return Integer.parseInt(getStrCurrDay());
    }

    public static final int getIntCurrHour() {
        return Integer.parseInt(getStrCurrHour());
    }

    public static final int getIntCurrMinute() {
        return Integer.parseInt(getStrCurrMinute());
    }

    public int getSeason() {
        int i = getIntCurrMonth();
        return 1 <= i && i <= 3?1:(4 <= i && i <= 6?2:(7 <= i && i <= 9?3:4));
    }

    public static int getDaysByYearMonth(int year, int month) {
        Calendar a = Calendar.getInstance();
        a.set(1, year);
        a.set(2, month - 1);
        a.set(5, 1);
        a.roll(5, -1);
        int maxDate = a.get(5);
        return maxDate;
    }

    public static String differDate(String dateStr) throws Exception {
        if(dateStr != null && !"".equals(dateStr)) {
            Calendar c = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
            Date date1 = sdf.parse(dateStr);
            c.setTime(date1);
            long day1 = c.getTimeInMillis();
            Date currentDate = new Date();
            c.setTime(currentDate);
            long day2 = c.getTimeInMillis();
            Double differDate2 = Double.valueOf((double)(day1 - day2) * 1.0D / 1000.0D / 60.0D / 60.0D / 24.0D);
            if(differDate2.doubleValue() >= 1.0D) {
                return differDate2.longValue() + "天";
            } else {
                differDate2 = Double.valueOf(differDate2.doubleValue() * 24.0D);
                return differDate2.doubleValue() >= 1.0D?differDate2.longValue() + "小时":(int)(differDate2.doubleValue() * 60.0D) + "分钟";
            }
        } else {
            return "";
        }
    }

    public static long getdatediff(String dt1, String dt2, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        long day = 100L;

        try {
            Date var6 = sdf.parse(dt1);
            Date mydate = sdf.parse(dt2);
            day = (var6.getTime() - mydate.getTime()) / 86400000L;
            return day;
        } catch (Exception var8) {
            var8.printStackTrace();
            return 100L;
        }
    }

    public static Date getAfterCountMonth(int monthCount) throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.add(2, monthCount);
        return calendar.getTime();
    }

    public static boolean getDateCompare(String dt1, String dt2, int day) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(df.parse(dt1));
        c2.setTime(df.parse(dt2));
        c1.add(5, day);
        int result = c1.compareTo(c2);
        return result <= 0;
    }

    public static Date getAfterSevenDay(int day) throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.add(5, day);
        return calendar.getTime();
    }

    public static String getAfterSevenDay(String str, int day) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(df.parse(str));
        calendar.add(5, day);
        return df.format(calendar.getTime());
    }

    public static String getAfterSevenMonth(String str, int day) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(df.parse(str));
        calendar.add(2, day);
        return df.format(calendar.getTime());
    }

    public static String getAfterSeDay(String str, int day) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(df.parse(str));
        calendar.add(5, day);
        return df.format(calendar.getTime());
    }

    public static int getMonth(Date start, Date end) {
        if(start.after(end)) {
            Date startCalendar1 = start;
            start = end;
            end = startCalendar1;
        }

        Calendar startCalendar11 = Calendar.getInstance();
        startCalendar11.setTime(start);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(end);
        Calendar temp = Calendar.getInstance();
        temp.setTime(end);
        temp.add(5, 1);
        int year = endCalendar.get(1) - startCalendar11.get(1);
        int month = endCalendar.get(2) - startCalendar11.get(2);
        return startCalendar11.get(5) == 1 && temp.get(5) == 1?year * 12 + month + 1:(startCalendar11.get(5) != 1 && temp.get(5) == 1?year * 12 + month:(year * 12 + month - 1 < 0?0:year * 12 + month));
    }

    public static long differDate1(String dateStr) throws Exception {
        if(dateStr != null && !"".equals(dateStr)) {
            Calendar c = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
            Date date1 = sdf.parse(dateStr);
            c.setTime(date1);
            long day1 = c.getTimeInMillis();
            Date currentDate = new Date();
            c.setTime(currentDate);
            long day2 = c.getTimeInMillis();
            Double differDate2 = Double.valueOf((double)(day1 - day2) * 1.0D / 1000.0D / 60.0D / 60.0D / 24.0D);
            return (long)(differDate2.doubleValue() * 60.0D * 60.0D * 24.0D);
        } else {
            return 0L;
        }
    }

    public static long differDate3(String dateStr) throws Exception {
        if(dateStr != null && !"".equals(dateStr)) {
            Calendar c = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
            Date date1 = sdf.parse(dateStr);
            c.setTime(date1);
            long day1 = c.getTimeInMillis();
            Date currentDate = new Date();
            c.setTime(currentDate);
            long day2 = c.getTimeInMillis();
            Double differDate2 = Double.valueOf((double)(day1 - day2) * 1.0D / 1000.0D / 60.0D / 60.0D / 24.0D);
            return (long)(differDate2.doubleValue() * 24.0D);
        } else {
            return 0L;
        }
    }

    public static long differDatetoMS(Date date1, Date date2) throws Exception {
        long time1 = date1.getTime();
        long time2 = date2.getTime();
        return time1 - time2;
    }

    public static int compare_date(String DATE1, String DATE2) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus hh:mm");

        try {
            Date var5 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            return var5.getTime() > dt2.getTime()?1:(var5.getTime() < dt2.getTime()?-1:0);
        } catch (Exception var51) {
            var51.printStackTrace();
            return 0;
        }
    }

    public static int compare_date(String DATE2) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");

        try {
            Calendar var6 = Calendar.getInstance();
            String currentDate = df.format(var6.getTime());
            Date dt1 = df.parse(DATE2);
            Date dt2 = df.parse(currentDate);
            return dt1.getTime() > dt2.getTime()?1:(dt1.getTime() < dt2.getTime()?-1:0);
        } catch (Exception var61) {
            var61.printStackTrace();
            return 0;
        }
    }

    public static int getCurrentPeriodNo(String firstOpenTime, long lPeriod) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        int currentPeriodNo = 0;

        try {
            Date var11 = df.parse(firstOpenTime);
            Date dt2 = df.parse(NowStr());
            long ldt1 = var11.getTime();
            long ldt2 = dt2.getTime();
            if(ldt1 <= ldt2) {
                currentPeriodNo = (int)((ldt2 - ldt1) / lPeriod * 3600L * 1000L + 1L);
            }
        } catch (ParseException var111) {
            var111.printStackTrace();
        }

        return currentPeriodNo;
    }

    public static int compareDate(String date) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus");

        try {
            Calendar var6 = Calendar.getInstance();
            String currentDate = df.format(var6.getTime());
            Date dt1 = df.parse(date);
            Date dt2 = df.parse(currentDate);
            return dt1.getTime() > dt2.getTime()?1:(dt1.getTime() < dt2.getTime()?-1:0);
        } catch (Exception var61) {
            var61.printStackTrace();
            return 0;
        }
    }

    public static int compareDate(String DATE1, String DATE2, String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);

        try {
            Date var6 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            return var6.getTime() > dt2.getTime()?1:(var6.getTime() < dt2.getTime()?-1:0);
        } catch (Exception var61) {
            var61.printStackTrace();
            return 0;
        }
    }

    public static String getDatetimetoStr(String dateStr) {
        String dateStr1 = "";
        if(dateStr != null && dateStr != "") {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");

            try {
                if(dateStr.indexOf("-") < 0) {
                    dateStr1 = DatetimetoStr(sdf.parse(dateStr));
                }
            } catch (Exception var4) {
                var4.printStackTrace();
            }
        }

        return dateStr1;
    }

    public static String getMonthFirstDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(5, calendar.getActualMinimum(5));
        return DatetoStr(calendar.getTime());
    }

    public static String getUpMonthFirstDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(2, -1);
        calendar.set(5, calendar.getActualMinimum(5));
        return DatetoStr(calendar.getTime());
    }

    public static String getMonthLastDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(5, calendar.getActualMaximum(5));
        return DatetoStr(calendar.getTime());
    }

    public static String getUpMonthLastDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(2, -1);
        calendar.set(5, calendar.getActualMaximum(5));
        return DatetoStr(calendar.getTime());
    }

    public static String getWeekFirstDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(7, 2);
        return DatetoStr(calendar.getTime());
    }

    public static String getWeekLastDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(7, 1);
        calendar.add(3, 1);
        return DatetoStr(calendar.getTime());
    }

    public static String getUpWeekFirstDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(4, -1);
        calendar.set(7, 2);
        return DatetoStr(calendar.getTime());
    }

    public static String getUpWeekLastDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(4, -1);
        calendar.set(7, 1);
        calendar.add(3, 1);
        return DatetoStr(calendar.getTime());
    }

    public static String getBeginDayOfYear() {
        Calendar cal = Calendar.getInstance();
        cal.set(1, getNowYear().intValue());
        cal.set(2, 0);
        cal.set(5, 1);
        return DatetoStr(cal.getTime());
    }

    public static String getEndDayOfYear() {
        Calendar cal = Calendar.getInstance();
        cal.set(1, getNowYear().intValue());
        cal.set(2, 11);
        cal.set(5, 31);
        return DatetoStr(cal.getTime());
    }

    public static Integer getNowYear() {
        Date date = new Date();
        GregorianCalendar gc = (GregorianCalendar)Calendar.getInstance();
        gc.setTime(date);
        return Integer.valueOf(gc.get(1));
    }

    public static String dateFormatConvert(String str) {
        String str2 = "";
        if(str != "" && str != null) {
            try {
                SimpleDateFormat var5 = new SimpleDateFormat("yyyyMMddHHmmss");
                Date d = var5.parse(str);
                SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
                str2 = f1.format(d);
                return str2;
            } catch (ParseException var51) {
                var51.printStackTrace();
                return str2;
            }
        } else {
            return str2;
        }
    }

    public static long differDate2(String dateStr) throws Exception {
        if(dateStr != null && !"".equals(dateStr)) {
            Calendar c = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
            Date date1 = sdf.parse(dateStr);
            c.setTime(date1);
            long day1 = c.getTimeInMillis();
            Date currentDate = new Date();
            c.setTime(currentDate);
            long day2 = c.getTimeInMillis();
            Double differDate2 = Double.valueOf((double)(day2 - day1) * 1.0D / 1000.0D / 60.0D / 60.0D / 24.0D);
            return differDate2.doubleValue() >= 1.0D?differDate2.longValue():-1L;
        } else {
            return -1L;
        }
    }

    public static String getDateStr(String date, long s) {
        String time = "";

        try {
            SimpleDateFormat var7 = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
            long timeStart = var7.parse(date).getTime();
            time = var7.format(new Date(timeStart + s));
        } catch (Exception var71) {
            var71.printStackTrace();
        }

        return time;
    }

    public static String getAfterHours(String date, int hours) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(df.parse(date));
        calendar.add(10, hours);
        return df.format(calendar.getTime());
    }

    public static final String DatetoStr2(Date date) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss");
        return simpledateformat.format(date);
    }

    public static String getDateStr(Date date, String s) {
        return (new SimpleDateFormat(s)).format(date);
    }

    public static String getDateStr(long l, String s) {
        return (new SimpleDateFormat(s)).format(new Date(l));
    }

    public static String getNow(String s) {
        return getDateStr(System.currentTimeMillis(), s);
    }

    public static Date getDate(String s, String s1, long l) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(s1);

        Date date;
        try {
            date = simpledateformat.parse(s);
        } catch (Exception var7) {
            date = new Date(l);
        }

        return date;
    }

    public static synchronized String getDatePattern() {
        defaultDatePattern = "yyyy-MM-selfAddMinus";
        return defaultDatePattern;
    }

    public static final String getDate(Date aDate) {
        SimpleDateFormat df = null;
        String returnValue = "";
        if(aDate != null) {
            df = new SimpleDateFormat(getDatePattern());
            returnValue = df.format(aDate);
        }

        return returnValue;
    }

    public static Date getDate(String s, String s1) {
        return getDate(s, s1, 0L);
    }

    public static long getTime(String s, String s1, long l) {
        return getDate(s, s1, l).getTime();
    }

    public static long getTime(String s, String s1) {
        return getTime(s, s1, 0L);
    }

    public static String convert(String s, String s1, String s2) {
        Date date = getDate(s, s1);
        return null == date?"":getDateStr(date, s2);
    }

    public static String convert(String s, String s1, String s2, char c) {
        char[] ac = s.toCharArray();

        for(int var8 = 0; var8 < ac.length; ++var8) {
            if(c == s.charAt(var8)) {
                ac[var8] = 45;
            }
        }

        Date var81 = getDate(new String(ac), s1.replace(c, '-'));
        char[] ac1 = null != var81?getDateStr(var81, s2.replace(c, '-')).toCharArray():new char[0];

        for(int j = 0; j < ac1.length; ++j) {
            if(c == s.charAt(j)) {
                ac1[j] = s.charAt(j);
            }
        }

        return new String(ac1);
    }

    public static String getSeason(String s, String s1) {
        String s2 = "";
        Date date = getDate(s, s1);
        GregorianCalendar gregoriancalendar = new GregorianCalendar();
        String s3 = "yyyy";
        SimpleDateFormat simpledateformat = new SimpleDateFormat(s3);
        s2 = s2 + simpledateformat.format(date);
        gregoriancalendar.setTime(date);
        return s2 + getSeason(gregoriancalendar.get(2));
    }

    private static String getSeason(int i) {
        switch(i) {
            case 0:
                return "01";
            case 1:
                return "01";
            case 2:
                return "01";
            case 3:
                return "02";
            case 4:
                return "02";
            case 5:
                return "02";
            case 6:
                return "03";
            case 7:
                return "03";
            case 8:
                return "03";
            case 9:
                return "04";
            case 10:
                return "04";
            case 11:
                return "04";
            default:
                return "";
        }
    }

    public static int getDayInterval(long l, long l1) {
        return (int)((l - l1) / 86400000L);
    }

    public static long addDays(long l, int i) {
        return l + (long)i * 86400000L;
    }

    public static long startOfDay(long l) {
        return getDate(getDateStr(l, "yyyyMMdd"), "yyyyMMdd").getTime();
    }

    public static long endOfDay(long l) {
        return startOfDay(l) + 86400000L - 1L;
    }

    public static String getDayOfWeekStr(long l) {
        GregorianCalendar gregoriancalendar;
        (gregoriancalendar = new GregorianCalendar()).setTimeInMillis(l);
        int i = gregoriancalendar.get(7);
        String s = "";
        switch(i) {
            case 1:
                s = "周日";
                break;
            case 2:
                s = "周一";
                break;
            case 3:
                s = "周二";
                break;
            case 4:
                s = "周三";
                break;
            case 5:
                s = "周四";
                break;
            case 6:
                s = "周五";
                break;
            case 7:
                s = "周六";
        }

        return s;
    }

    public static boolean checkCurTimeIsAPeriod(String startTime, String endTime) {
        Date nowTime = new Date();
        String time = nowTime.getHours() + ":" + nowTime.getMinutes();
        return time.compareTo(startTime) >= 0 && time.compareTo(endTime) <= 0;
    }

    public static String get14StrCurrentTime() {
        Date date = new Date();
        String s = "";
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd");
        s = s + simpledateformat.format(date);
        simpledateformat = new SimpleDateFormat("HHmmss");
        return s + simpledateformat.format(date);
    }

    public static String get14StrTime(Calendar calendar) {
        Date date = calendar.getTime();
        String s = "";
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd");
        s = s + simpledateformat.format(date);
        simpledateformat = new SimpleDateFormat("HHmmss");
        return s + simpledateformat.format(date);
    }

    public static String getTimeStrBySplitor(String s, String s1) {
        return s != null && s.length() >= 8?(s.length() < 14?s.substring(0, 4) + s1 + s.substring(4, 6) + s1 + s.substring(6, 8):s.substring(0, 4) + s1 + s.substring(4, 6) + s1 + s.substring(6, 8) + " " + s.substring(8, 10) + ":" + s.substring(10, 12) + ":" + s.substring(12, 14)):s;
    }

    public static String getCurrentDate() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-selfAddMinus");
        String today = formatter.format(cal.getTime());
        return today;
    }

    public static String getYesterday() {
        Calendar cal = Calendar.getInstance();
        cal.add(5, -1);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-selfAddMinus");
        String yesterday = formatter.format(cal.getTime());
        return yesterday;
    }

    public static String getDateFormString(String s) {
        SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-selfAddMinus");
        String dateTime = dateFm.format(new Date(s));
        return dateTime;
    }

    public static Date reverse2Date(String date) {
        SimpleDateFormat simple = null;
        switch(date.trim().length()) {
            case 8:
                simple = new SimpleDateFormat("HH:mm:ss");
                break;
            case 10:
                simple = new SimpleDateFormat("yyyy-MM-selfAddMinus");
                break;
            case 19:
                simple = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        }

        try {
            return simple.parse(date.trim());
        } catch (ParseException var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static java.sql.Date reverse2SqlDate(String date) {
        SimpleDateFormat simple = null;
        switch(date.trim().length()) {
            case 8:
                simple = new SimpleDateFormat("HH:mm:ss");
                break;
            case 10:
                simple = new SimpleDateFormat("yyyy-MM-selfAddMinus");
                break;
            case 19:
                simple = new SimpleDateFormat("yyyy-MM-selfAddMinus HH:mm:ss");
        }

        try {
            java.sql.Date var3 = new java.sql.Date(simple.parse(date.trim()).getTime());
            return var3;
        } catch (ParseException var31) {
            var31.printStackTrace();
            return null;
        }
    }

    public static Date stringtoDate(String dateStr, String format) {
        Date d = null;
        if(dateStr != null && dateStr.trim().length() > 0) {
            SimpleDateFormat formater = new SimpleDateFormat(format);

            try {
                formater.setLenient(false);
                d = formater.parse(dateStr);
            } catch (Exception var5) {
                d = null;
            }
        }

        return d;
    }

    public static java.sql.Date getBeforeAfterDate(String datestr, int day) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-selfAddMinus");
        java.sql.Date olddate = null;

        try {
            df.setLenient(false);
            olddate = new java.sql.Date(df.parse(datestr).getTime());
        } catch (ParseException var9) {
            throw new RuntimeException("日期转换错误");
        }

        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(olddate);
        int Year = cal.get(1);
        int Month = cal.get(2);
        int Day = cal.get(5);
        int NewDay = Day + day;
        cal.set(1, Year);
        cal.set(2, Month);
        cal.set(5, NewDay);
        return new java.sql.Date(cal.getTimeInMillis());
    }

    public static int getDaysBetween(String beginDate, String endDate, String dateformat) {
        try {
            SimpleDateFormat var10 = new SimpleDateFormat(dateformat);
            Date bDate = var10.parse(beginDate);
            Date eDate = var10.parse(endDate);
            GregorianCalendar d1 = new GregorianCalendar();
            d1.setTime(bDate);
            GregorianCalendar d2 = new GregorianCalendar();
            d2.setTime(eDate);
            int days = d2.get(6) - d1.get(6);
            int y2 = d2.get(1);
            if(d1.get(1) != y2) {
                Calendar d11 = (Calendar)d1.clone();

                do {
                    days += d11.getActualMaximum(6);
                    d11.add(1, 1);
                } while(d11.get(1) != y2);
            }

            return days;
        } catch (ParseException var11) {
            var11.printStackTrace();
            return 0;
        }
    }

    public static int getDaysBetween(String beginDate, String endDate) {
        return getDaysBetween(beginDate, endDate, "yyyy-MM-selfAddMinus");
    }

    public static String rerverObjectDate(String obj) {
        String s1 = null;

        try {
            SimpleDateFormat var10 = new SimpleDateFormat("EEE MMM selfAddMinus hh:mm:ss z yyyy", Locale.ENGLISH);
            Date date = var10.parse(obj);
            s1 = DatetoStr1(date);
            return s1;
        } catch (ParseException var4) {
            var4.printStackTrace();
            return "";
        }
    }

    public static boolean checkMonthFirstDay() {
        Calendar c = Calendar.getInstance();
        int today = c.get(5);
        return today == 1;
    }
}
